#Array Initialisation in Java
Explore tagged Tumblr posts
tpointtech1 · 10 days ago
Text
Common Mistakes When Initializing Arrays in Java and How to Avoid Them
Learn the common mistakes developers make when initializing arrays in Java and how to avoid them. Master proper array initialization techniques and write cleaner, error-free Java code with this beginner-friendly guide.
1 note · View note
blocks2code · 2 years ago
Text
ArrayList Class in Java With Program Example
Arraylist is a child class of AbstractList and implements List interface. It represents dynamic array that can grow or shrink as needed. In case of standard array, one must know the number of elements about to store in advance. In other words, a standard array is fixed in size and its size can’t be changed after its initialisation. To overcome this problem, collection framework provides…
Tumblr media
View On WordPress
2 notes · View notes
movelikekeith · 6 years ago
Text
import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import ddf.minim.signals.*; import ddf.minim.spi.*; import ddf.minim.ugens.*;
// importation des librairies kinect import kinect4WinSDK.Kinect; import kinect4WinSDK.SkeletonData;
//variables de son Minim minim; AudioPlayer player;
//création d'une variable nommée kinect Kinect kinect;
//ArrayList est une implémentation de tableau redimensionnable de l'interface Java List. ArrayList <SkeletonData> bodies;
// déclarer les variable image PImage Tete; PImage Buste; PImage BrasDroitHaut; PImage BrasGaucheHaut; PImage BrasDroitBas; PImage BrasGaucheBas; PImage JambeDroiteHaut; PImage JambeGaucheHaut; PImage JambeDroiteBas; PImage JambeGaucheBas;
//déclarer autres variables // variable indiquant le degré trouvé float Angle = 0; // variables des coordonnées des articulations //_j1 et_j2 variables qui relient deux articulations int _j1, _j2 ;
//variables fonds d'écrans aléatoires float fondAleatoire ; int fragNumber ; //variables des fonds PImage Fond1;
void setup() {
 size(1280, 960);  //initialisation de la kinect  kinect = new Kinect(this);  //lisser  smooth();  //déclaration de la liste en tableau  bodies = new ArrayList<SkeletonData>();
 //jouer le son  minim = new Minim(this);  player = minim.loadFile("groove.mp3");  player.play();
 //chargement des images de membres, en l'occurence la partie haute du bras droit  Tete= loadImage ("Tete.png");  Buste= loadImage ("Buste.png");  BrasDroitHaut = loadImage ("BrasDroitHaut.png");  BrasGaucheHaut= loadImage ("BrasGaucheHaut.png");  BrasDroitBas= loadImage ("BrasDroitBas.png");  BrasGaucheBas= loadImage ("BrasGaucheBas.png");  JambeDroiteHaut= loadImage ("JambeDroiteHaut.png");  JambeGaucheHaut= loadImage ("JambeGaucheHaut.png");  JambeDroiteBas= loadImage ("JambeDroiteBas.png");  JambeGaucheBas= loadImage ("JambeGaucheBas.png"); }
void draw() {  //background (255);  Fond1 = loadImage("Fond1.png");
 //image (Fond, 0, 0, Fond.width*2, Fond.width*2) ;  image (Fond1, 0, 0) ;  smooth();
 //fait tourner le programme autant de fois qu'il y a de squelettes/de personnes détectées  for (int i=0; i<bodies.size (); i++)  {    //les bodies sont extraits de la array list  avec "get"    //dessine squellette en haut gauche    drawSkeleton(bodies.get(i));    //cherche où est le squelette    drawPosition(bodies.get(i));  } }
void drawPosition(SkeletonData _s) {  noStroke();  fill(0, 100, 255);  //liste des points en mouvement du squelette?  String s1 = str(_s.dwTrackingID); }
void drawSkeleton(SkeletonData _s) {  // Body
 //BUSTE  DrawBoneBuste(_s,    Kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER,    Kinect.NUI_SKELETON_POSITION_SPINE);
 // TÊTE  DrawBoneTete(_s,    Kinect.NUI_SKELETON_POSITION_HEAD,    Kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER);
 // Left Arm  // BRAS HAUT GAUCHE  DrawBoneBrasGaucheHaut(_s,    Kinect.NUI_SKELETON_POSITION_SHOULDER_LEFT,    Kinect.NUI_SKELETON_POSITION_ELBOW_LEFT);  
 // BRAS BAS GAUCHE  DrawBoneBrasGaucheBas(_s,    Kinect.NUI_SKELETON_POSITION_ELBOW_LEFT,    Kinect.NUI_SKELETON_POSITION_WRIST_LEFT);
 // Right Arm  // BRAS HAUT DROITE  DrawBoneBrasDroitHaut(_s,    Kinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT,    Kinect.NUI_SKELETON_POSITION_ELBOW_RIGHT);
 // BRAS BAS DROITE  DrawBoneBrasDroitBas(_s,    Kinect.NUI_SKELETON_POSITION_ELBOW_RIGHT,    Kinect.NUI_SKELETON_POSITION_WRIST_RIGHT);
 // Left Leg  // HAUT JAMBE GAUCHE  DrawBoneJambeGaucheHaut(_s,    Kinect.NUI_SKELETON_POSITION_HIP_LEFT,    Kinect.NUI_SKELETON_POSITION_KNEE_LEFT);
 // BAS JAMBE GAUCHE  DrawBoneJambeGaucheBas(_s,    Kinect.NUI_SKELETON_POSITION_KNEE_LEFT,    Kinect.NUI_SKELETON_POSITION_ANKLE_LEFT);
 // Right Leg  // HAUT JAMBE DROITE  DrawBoneJambeDroiteHaut(_s,    Kinect.NUI_SKELETON_POSITION_HIP_RIGHT,    Kinect.NUI_SKELETON_POSITION_KNEE_RIGHT);
 // BAS JAMBE DROITE  DrawBoneJambeDroiteBas(_s,    Kinect.NUI_SKELETON_POSITION_KNEE_RIGHT,    Kinect.NUI_SKELETON_POSITION_ANKLE_RIGHT); } /* //void draw bone dessinant la base du squelette filaire en jaune // à réactiver si besoin de repères
void DrawBone(SkeletonData _s, int _j1, int _j2) { noFill(); stroke(255, 255, 0); if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED && _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
//Option épaissir ligne strokeWeight(2); line(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1, _s.skeletonPositions[_j2].y*height/1); } } */
// void Drawbone à décliner pour chaque membre // BRAS HAUT DROIT void DrawBoneBrasDroitHaut(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT ;    _j2 =  Kinect.NUI_SKELETON_POSITION_ELBOW_RIGHT ;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*Option épaissir ligne : A ENLEVER A LA FIN     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(BrasDroitHaut, -BrasDroitHaut.width/4, -BrasDroitHaut.width/4, BrasDroitHaut.width/2, longB+BrasDroitHaut.width/3.2);    popMatrix();
   // line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
// BRAS HAUT GAUCHE void DrawBoneBrasGaucheHaut(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_SHOULDER_LEFT ;    _j2 =  Kinect.NUI_SKELETON_POSITION_ELBOW_LEFT ;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   //Option épaissir ligne    //strokeWeight(2);    // repère à supprimer plus tard    /* line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(BrasGaucheHaut, -BrasGaucheHaut.width/4, -BrasGaucheHaut.width/4, BrasGaucheHaut.width/2, longB+BrasGaucheHaut.width/3.2);    popMatrix();
   //  line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
// BUSTE void DrawBoneBuste(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER ;    _j2 =  Kinect.NUI_SKELETON_POSITION_SPINE ;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*    //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(Buste, -Buste.width/4, -Buste.width/10, Buste.width/2, longB+Buste.width/2.5);    popMatrix();
   // line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
// TÊTE void DrawBoneTete(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_HEAD ;    _j2 =  Kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER ;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*    //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(Tete, -Tete.width/4, -Tete.width/4, Tete.width/2, longB+Tete.width/4);    //Test sans LongB    //image(Tete, _s.skeletonPositions[_j1].x*width/1,_s.skeletonPositions[_j1].y*height/1);    popMatrix();
   //  line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
//BRAS GAUCHE BAS void DrawBoneBrasGaucheBas(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_ELBOW_LEFT ;    _j2 =  Kinect.NUI_SKELETON_POSITION_WRIST_LEFT;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*   //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(BrasGaucheBas, -BrasGaucheBas.width/3, -BrasGaucheBas.width/8, BrasGaucheBas.width/2, longB+BrasGaucheBas.width/4);    popMatrix();
   //line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
void appearEvent(SkeletonData _s) {  if (_s.trackingState == Kinect.NUI_SKELETON_NOT_TRACKED)  {    return;  }  synchronized(bodies) {    //objets ajoutés à l'array list    bodies.add(_s);  } }
// BRAS BAS DROITE void DrawBoneBrasDroitBas(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_ELBOW_RIGHT;    _j2 =  Kinect.NUI_SKELETON_POSITION_WRIST_RIGHT;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*   //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(BrasDroitBas, -BrasDroitBas.width/7, -BrasDroitBas.width/8, BrasDroitBas.width/2, longB+BrasDroitBas.width/4);    popMatrix();
   //line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
void disappearEvent(SkeletonData _s) {  synchronized(bodies) {    //la commande size importe le nombre actuel d'éléments dans la liste    for (int i=bodies.size ()-1; i>=0; i--)    {      //si ??? les les bodies sont extraits de la array list avec "get" + tracking id ???      if (_s.dwTrackingID == bodies.get(i).dwTrackingID)      {        // on peut supprimer les informations "bodies" d'une array list en utilisant remove        bodies.remove(i);      }    }  } }
//JAMBE GAUCHE HAUT void DrawBoneJambeGaucheHaut(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_HIP_LEFT;    _j2 =  Kinect.NUI_SKELETON_POSITION_KNEE_LEFT;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*   //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(JambeGaucheHaut, -JambeGaucheHaut.width/3, -JambeGaucheHaut.width/8, JambeGaucheHaut.width/1.8, longB+JambeGaucheHaut.width/4);    popMatrix();
   //  line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
// JAMBE GAUCHE BAS void DrawBoneJambeGaucheBas(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_KNEE_LEFT ;    _j2 =  Kinect.NUI_SKELETON_POSITION_ANKLE_LEFT ;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*   //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(JambeGaucheBas, -JambeGaucheBas.width/2.5, -JambeGaucheBas.width/8, JambeGaucheBas.width/1.8, longB+JambeGaucheBas.width/4);    popMatrix();
   //line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
//JAMBE DROITE HAUT void DrawBoneJambeDroiteHaut(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_HIP_RIGHT ;    _j2 =  Kinect.NUI_SKELETON_POSITION_KNEE_RIGHT ;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /*    //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);     */
   // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(JambeDroiteHaut, -JambeDroiteHaut.width/5, -JambeDroiteHaut.width/8, JambeDroiteHaut.width/1.8, longB+JambeDroiteHaut.width/4);    popMatrix();
   //line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
//JAMBE DROITE BAS void DrawBoneJambeDroiteBas(SkeletonData _s, int _j1, int _j2) {  noFill();  stroke(255, 255, 0);  if (_s.skeletonPositionTrackingState[_j1] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED &&    _s.skeletonPositionTrackingState[_j2] != Kinect.NUI_SKELETON_POSITION_NOT_TRACKED) {
   _j1 = Kinect.NUI_SKELETON_POSITION_KNEE_RIGHT ;    _j2 =  Kinect.NUI_SKELETON_POSITION_ANKLE_RIGHT ;    //reconnnait pas la variable _s    float longB = dist(_s.skeletonPositions[_j1].x*width/1,      _s.skeletonPositions[_j1].y*height/1,      _s.skeletonPositions[_j2].x*width/1,      _s.skeletonPositions[_j2].y*height/1);
   /* //Option épaissir ligne     //strokeWeight(2);     // repère à supprimer plus tard     line(_s.skeletonPositions[_j1].x*width/1,     _s.skeletonPositions[_j1].y*height/1,     _s.skeletonPositions[_j2].x*width/1,     _s.skeletonPositions[_j2].y*height/1);
    */    // Calcul de l'angle selon position des points    Angle = atan2(_s.skeletonPositions[_j2].y*height/1- _s.skeletonPositions[_j1].y*height/1, _s.skeletonPositions[_j2].x*width/1-_s.skeletonPositions[_j1].x*width/1);    // Converti en degrés    println(degrees(Angle));
   pushMatrix();    // La translation redéfinit (x1;y1) en origine (0;0)    translate(_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j1].y*height/1);    //rotate(radians(-Angle));
   pushMatrix();    // -PI/2 permet la rotation de l'image verticale vers l'horizontale        rotate((Angle)-PI/2);    //println(-Angle);    // Afficher l'image et la ligne selon angle    image(JambeDroiteBas, -JambeDroiteBas.width/8, -JambeDroiteBas.width/8, JambeDroiteBas.width/1.8, longB+JambeDroiteBas.width/4);    popMatrix();
   //line(0, 0, _s.skeletonPositions[_j2].x*width/1 -_s.skeletonPositions[_j1].x*width/1, _s.skeletonPositions[_j2].y*height/1-_s.skeletonPositions[_j1].y*height/1);    popMatrix();  } }
void moveEvent(SkeletonData _b, SkeletonData _a) {  if (_a.trackingState == Kinect.NUI_SKELETON_NOT_TRACKED)  {    return;  }  synchronized(bodies) {    for (int i=bodies.size ()-1; i>=0; i--)    {      //si ??? les les bodies sont extraits de la array list avec "get" + tracking id ???      if (_b.dwTrackingID == bodies.get(i).dwTrackingID)      {        //les bodies sont extraits de la array list avec "get"        bodies.get(i).copy(_a);        break;      }    }  } }
1 note · View note
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:               service_time  =  (tally_time  x  efficiency)  +  payment_time            where:                   tally_time:  time it takes to tally up the customer's goods                   efficiency:  the efficiency of the server                  payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue
Tumblr media
Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.
Tumblr media
Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()             Declare variables and instances and do initialisations             Open the input data file;  if not found print error and exit           Read first CustomerArrival event from file and add it to the event queue      While the event queue is not empty . . .                        Get the next event from the event queue and set CrntTime to the event time                            If the event type = CustomerArrival event . . .                                            if an idle server is available . . .                                                    Find fastest idle serve                                                      set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                   add ServerFinish event to the event queue                                  Else                                           Add event's customer to the customer queue                                  End if                                  If not EOF . . .                                                    Read next customer arrival from file                                        add CustomerArrival event to the event queue                                  End if                        Else // event type must be a ServerFinish event . . .                                      Get server no. from event, set server to idle and do server's stats                               If customer queue is not empty . . .                                                    Get next customer from the customer queue                                                  Find fastest idle serve                                                     set the server’s idle flag to busy.                                            calculate the server’s finish time                                                add ServerFinish event to the event queue                                  End if                       End if            End while             Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java: javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.  
Marking Guide
Marks will be awarded for the appropriate use of data structures and the efficiency of the program at processing the input and producing the correct output. Marks may be deducted for untidy or poorly designed code. Appropriate comments should be provided where needed. There will be a deduction of up to 4 marks for using STL, or equivalent libraries, rather than coding the data structures and algorithms yourself. You may use string or String type for storing words or text, if you wish. All coding and comments must be your own work.   Submission: Assignments should be typed into a single text file named "ass2.ext" where "ext" is the appropriate file extension for the chosen language. You should run your program and copy and paste the output into a text file named: "output.txt"   Submit your files via the submit program on banshee:                  submit -u user -c csci203 -a 2 ass1.ext output.txt      - where user is your unix userid and ext is the extn of your code file. Late assignment submissions without granted extension will be marked but the points awarded will be reduced by 1 mark for each day late.  Assignments will not be accepted if more than five days late. An extension of time for the assignment submission may be granted in certain circumstances.  Any request for an extension of the submission deadline must be made via SOLS before the submission deadline. Supporting documentation should accompany the request for any extension. Read the full article
0 notes
techandguru-blog · 6 years ago
Link
Did you see a basket full of apples? What did you notice? 1. All the items in the basket are apple (same type). 2. All items are present side by side (continuous memory/space) and 3. The size of the basket is fixed and predefined i.e. size of basket can not auto expand to accommodate more items than its capacity. In the same way, in Java, we have Java arrays. The array is a collection of same type items. The size of the array is defined at declaration and can not change after that. Hope you got the idea of array pretty much. In this post, we will learn Java arrays and array usages in detail.
SO WHAT IS AN ARRAY?
So as defined earlier, an array is a fixed size collection of items of the same type. Here are important points about an array:
- All items in the array are of the same type
 - An array can have duplicate items
- Size of an array is fixed and defined at instantiating time.
- Depending upon memory allocation, items are present in continuous memory space.
- Memory allocation to array is dynamic in Java i.e. memory is allocated automatically.
- Items in the array are ordered
- The array is a direct subclass of Object
- Every Array implementation implements Cloneable and Serializable interface.
- An array can be declared using "[]". e,g String[] arrayVar;
- An array can store primitive and object type both
- If the array store object then the actual objects are allocated memory in HEAP
Tumblr media
Java Array and Indexing
CREATING, INITIALISING AND ACCESSING AN ARRAY
ONE DIMENSION ARRAY:
One dimensional array is can be declared like 
type var-name[]; OR type[] var-name;
Array declaration contains type and variable name. Type of array tells which kind of items can be stored in the array. The type could be primitive or Object. Let's see examples of array declaration
byte[] byteArr;  //byte array
int[] intArr;   //can store int only
long[] longArr; // can store long
String[] stringArray;  //can store strings only
Object[] objectArray; //can store items of type objects..literally any type in java
Above arrays are declared only i.e. such variable are not given any memory and nothing is actually existing for them. It just tells the compiler that such items/variables are declared. 
INSTANTIATING AN ARRAY
- declaring an array just create reference only but no memory allocation. Proces of allocating memory to array is called array instantiation.
- an array can be instantiated like e.g.  Type[] arr = new Type[sizeofarra];
- Type tells the type of array items
- sizeofarra is the size of the array it tells how many items can be stored in the array at max
- Index of items in an array starts at 0 and goes till (size of the array - 1)
e.g. 
intArr = new int[20]; // allocating memory to the array intArr declared above - default values of array items are 0, false and null for Number type, boolean and object respectively.
INITIALIZING ARRAY WITH VALUES AT DECLARATION: ARRAY LITERAL
- The array can be declared and initialized using
int[] arr = {1,2,3,4,5,6,78,8};
- Above statement, does declaration, instantiation, and initialization automatically. You need not specify "new type[size]" etc.
- arrays in java can be easily iterated using loops and even Java above 5 provide optimized syntax to traverse array item like below
foreach(Type item in items){  //items is an array of type Type //can manipulate item here  }
- If an attempt is made to access elements outside the array, you will encounter ArrayIndexOutOfBoundsException on runtime.
MULTIDIMENSIONAL ARRAY
- An array could be multidimensional i.e. each item of an array will contain a reference to one dimension lower array as that of a parent. e.g. int[][][] items is 3-D array; So items[0] will refer to int[][] array and items[0][0] will refer to int[] and item[1][0][0] will actually contain int value.
Tumblr media
Java Multidimensional Array
- an array can be passed as an ARGUMENT OF THE FUNCTION USING ARRAY VARIABLE NAME ONLY.
- an array can be returned from a function using an array variable name.
- an array can contain the object of any valid java type or user-defined.
CLONING A JAVA ARRAY
an array can be cloned. Cloning is a process to deep copy I,e means an exact replica of the original array is created and cloned instance contains the exact item rather than the reference of the parent array items.
e.g. int[] arra = new int[10].
int[] clonedarra = arra.clone();
now arra and clonearra are two different arrays in memory with exactly the same items but a different copy.
USAGES:
- the array can be used when we know the max items to be stored.
- when items to be stored are of the same type
You may like to visit other Java Basic Concepts
Oh! you reached the end of the article. Hope you like, please share, subscribe and comment.
0 notes
assignmentsolutions4me · 7 years ago
Text
ITC538 | Final Exam Java| Java
Rationale
To assess students' understanding of the fundamental concepts of the subject material; their ability to integrate and apply information from various topics; and to apply their understanding and knowledge to simple problems.
Requirements
You are required to sit and pass the final exam in this subject to be eligible for a passing grade. The exam is worth 50% of the marks in this subject and you are required to answer following number of questions:
30 multiple-choice questions worth 45 marks
3 short-answer questions worth 25 marks each
Number of marks:  120 marks
The final exam will cover all the subject's topics.
SAMPLE EXAMINATION
INSTRUCTIONS TO CANDIDATES:
Enter your name, student number and signature into the box below.
Attempt ALL questions.
Start a new page for each new question, but NOT for each part of a question.
Read each question carefully to ensure that you have answered everything that is required in the question. Most questions have multiple parts.
There are 120 possible marks for this examination.
This examination is worth 50% of the final assessment for this subject.
INSTRUCTIONS TO INVIGILATORS:
Question paper May not be retained by the candidate
PART A – Multiple-choice Questions (Total Marks 45)
In this part there are 30 questions each worth 1.5marks.
Select what you consider to be the correct answer for each question and mark it on the supplied answer sheet using a lead pencil.
Make sure that you put your name and student number on the answer sheet. The question sheet and the answer sheet are to be returned with the rest of the examination paper.
A full sample of multiple choice questions is not available for release. The following questions provide an indication of the style of multiple choice questions.
What of the following is a valid identifier?
radius
8+9
class
$343
What is output by the following code?
int x = 2, y = 5;
if ((x < 5) && (y != 5))
System.out.println(x/y);
else if ((x > 3) || (y < 10))
System.out.println(x – y);
else
System.out.println(x + y);
01
7
-3
Analyse the following code.
boolean even = ((231 % 2) == 0);
if (even == true)
System.out.println("It is even!");
else
System.out.println("It is odd!");
Which of the following is true?
The program has a syntax error
The program displays "It is even!"
The program has a run-time error
The program displays "It is odd!"
What is y after the following switch statement?
int x = 0;
int y = 2;
switch (x + 1) {
case 0: y = 0;
case 1: y = 1;
default: y = -1;
}
2
01
-1
What is output by the following code? int x = 1, y = 2;
while (x <= 11) {
y += 2;
x += y
System.out.print(x + " " + y + " ");
}
5 4 6 11
5 4 11 6 19 8
4 5 6 11
3 4 10 8 19
What is output by the following code?
for (int i=0; i < 5; ++i)
System.out.print(i*2 + ", ");
0, 1, 2, 3, 4,
0, 2, 4, 6,
0, 2, 4, 6, 8,
2, 4, 6, 8, 10,
What is the effect of the following code?
int balance = 10;
while (balance > =1) {
if (balance < 9) break;
balance = balance – 9;
}
After the code, balance has the value 1
After the code, balance has the value 10
After the code, balance has the value -1
After the code, balance has the value 2
The header of a method is specified as: int func(double x)
Which of the following expressions or statements contains an illegal method call?
return func(2);
func(1+2.2)
func(func(2.5))
out.print(func());
What is the output by the following code?
char ch1 = 'A';
System.out.println(ch1 + " + 4 is " + (ch1 + 4));
A + 4 is E
A + 4 is 69
A + 4 is A4
A + 4 is 654
The variable tax has been declared of type double and has the value 19.257. For the expression (int)(tax*100)/100.0
which of the following is true?
It is illegal
Its value is 19
Its value is 19.25
Its value is 0.0
A programmer has written the following method to swap the values of two arguments passed to it.
static void swap(int x, int y) {
int temp = x;
x = y;
y = temp;
}
Which of the following is true for this method?
It will cause a compilation error
It will compile and execute as intended
It will cause a run-time error
It will cause a logic error
A programmer has written a hypotenuse method, which is used as follows:
int x = 3, y = 6;
double length = hypotenuse(x, y);
The header for the hypotenuse method is:
void hypotenuse(x, y)
double hypotenuse(a, b)
void hypotenuse(int x, int y)
double hypotenuse(int a, int b)
Overloading in Java allows:
methods in a class to have the same name but different parameter lists
variables in different methods to have the same name
methods inherited from a superclass to be modified
a memory location to be used for different variables at different times
The keyword used to make a variable belong to a class, rather than to each instance of a class is:
import
class
static
final
A programmer has written a method named fillIt to initialise the elements of an array of integers.
The programmer uses the method as follows:
int[] numbers = new int[20];
fillIt(numbers);
Which of the following is true?
The array object must be constructed inside the method, not outside it
The elements of an array cannot be initialised using a method
The design is correct
If the array object is constructed outside the method, a reference must be returned
PART B – Short-Answer Questions (Total Marks 75)
In answering the questions in this part, you may assume the existence of any standard data entry classes you typically use, such as Scanner.
Question 1 (25 marks)
(a) (Computing x) Approximate the value of a quantity x using the following series:
x = 1 + 1/2 + 1/3 + 1/4+....+1/n where n is a positive integer. The value of n should be passed to the
method.
Write a java method that calculates and displays the value of x for n (for example n = 1000). [7 marks]
(Area of regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is
where n is the number of sides and s is the side of the polygon.
Write a Java method that returns the area of a regular polygon using the following header:
public static double area(int n, double side).
(Hints: You may need Math.tan() function and Math.PI for area calculations.)
[9 marks]
(c) (Rectangle class) Design a class to represent a rectangle. The class is specified as follows:
Two double data fields named width and height hold the width and height of the rectangle. The default values are 1 for both width and height.
A no-arg constructor creates a default rectangle.
Getter and setter methods are provided for all data fields.
Accessor methods return the area and the perimeter.         [9 marks]
Question 2 (25 marks)
(a) Write the code for an Employee class, which has the following fields:
private String name;
private double salary;
Your class should contain the following:
Provide a constructor to set the employee’s name using a passed argument and also to set the salary to $0.
Provide a constructor that accepts arguments to set the employee’s name and salary. The salary should be set using the mutator method for salary described below.
Provide a mutator (i.e. setter) method for the salary that ensures the salary remains within the inclusive range $0 to $100,000. If an attempt is made to set a salary outside this range the current salary will not be changed.
Provide accessor (i.e. getter) methods for the name and for the salary. (15 marks)
(b) Write a program, called TestEmployee.java, to do the following:
Create an employee object referenced by emp1, using the name “Fred”.
Assign a salary of $45,000 for employee “Fred”.
Create an employee object referenced by emp2, using the name “Sue” and assigns her a salary of $55,000, all in the one statement.
On a separate line for each employee, display the employee’s name and 40% of the salary, for taxation purposes. (10 marks)
Question 3 (25 marks)
The following incomplete WordList class is intended as a collection class for holding a list of words.
class WordList {
private static final int DEFAULTSIZE = 100;
private int maxWords;
private String[] list;
private int length;
}
Here the constant provides a default value to replace any request for an illegal array size, the array provides a place to store the words, maxWords will record the size of the array, and length will record how many words are currently stored in it.
Write a constructer for WordList that accepts a parameter for the size of the array. The constructor will create an array for the words of the requested size, or of the default size if the size requested is not appropriate. It will also record the size of the array and set the current length appropriately. (5 marks)
Write a method addWord to add a word to the array. This will accept a String reference and return a Boolean value indicating whether or not the word in the String was able to be added. It should update the state of the collection object as appropriate. Note that a String object is immutable and can be added safely to the collection without needing to be copied. (10 marks)
Write a method findWord to find the first occurrence in the collection of a word beginning with a specified prefix. This method will accept a reference to a String object containing the prefix and return a String reference to the word found, or null if there is no matching word. The String class contains a startsWith instance method, which accepts a String argument and returns a boolean indicating whether the instance string starts with the argument string. (10 marks)
Material provided by the University
1 x 12pp Answer Booklet
General Purpose Answer Sheet
Material required by the student
Writing implements
2B Pencil and Eraser
Assessment Information
Learning materials
How to apply for special consideration
Academic regulations provide for special consideration to be given if you suffer misadventure or extenuating circumstances during the session (including the examination period) which prevents you from meeting acceptable standards or deadlines. Find the form on the Student Portal page.
Extensions
In order to ensure that students who hand their assignments in on time are not disadvantaged, and to enable me to comply with the requirement to return assignments to the class within 15 working days, the following rules about extensions will be strictly enforced:
Extensions cannot be granted for online tests, as these have to be done within a specific time frame, after which the answers are released to the class automatically.
Computer problems (such as the speed of your computer and the time it may take you to upload assignments onto TURNITIN) and normal work-related pressures and family commitments do not constitute sufficient reasons for the granting of extensions.
If it becomes obvious that you are not going to be able to submit an assignment on time because of an unavoidable problem, you must submit your request for an extension, prior to the due date, either by writing (email is acceptable) to your lecturer/subject coordinator or via the Request for Special Consideration form.
You are encouraged to make requests via email (especially for urgent requests), since the processing time for applications made through the online form can be a few days. Requests for extensions will not be granted on or after the due date so you must make sure that any extension is requested prior to the day on which the assignment is due.
You are expected to do all you can to meet assignment deadlines. Work and family- related pressures do not normally constitute sufficient reasons for the granting of extensions or incomplete grades.
If you apply for an extension, you may be asked to email your lecturer/subject coodinator on what you have done so far on the assignment.
You must be able to provide documentary evidence (such as a certificate from a doctor or counsellor) justifying the need for an extension as soon as practicable - but please note that if the circumstances giving rise to the request for an extension arise on a day when you cannot get documentary evidence, you must still apply for the extension before the due date and submit the documentary evidence afterwards.
Given the tight deadlines involved in returning assignments to students and putting feedback on Interact, the maximum extension granted generally will be seven (7) days from the due date.
Assignments received more than 10 days after the due date or extension date will not be marked unless the staff member decides otherwise. Items received late will be penalised at 10% of the mark available for the assessment item per day it is late (see below).
Note that for purposes of measuring lateness, the 'day' begins just after 00.00 hrs AEST - so an assignment received after midnight of the due date will be penalised 10% for lateness. This rule will be applied to all students uniformly.
Penalties for Late Submission
The Faculty of Business has determined that the penalty for the late submission of an assessment task (without obtaining the Subject Coordinator's approval for an extension) will be:
10% deduction per day, including weekends, of the maximum marks allocated for the assessment task, i.e. 1 day late 10% deduction, or 2 days late 20% deduction.
An example of the calculation would be:
Maximum marks allocated = 20
Penalty for one day late = 2 marks (so, a score of 18/20 becomes 16/20 and a score of 12/20 becomes 10/20).
If an assignment is due on a Friday but is not submitted until the following Tuesday, then the penalty will be four days (40% deduction or 8 marks in the example above).
Submissions more than 10 days late will be acknowledged as received but will not be marked.
Resubmission
Under normal circumstances resubmission of assessment items will not be accepted for any of the assessments required in this subject.
Online Submission
Assignments should be submitted through TurnItIn. Please meet with your respective lecturer to enroll in the Turnitin (If you do not receive any email from Turnitin for this subject).
Assessments such as Blogs, Quizzes, Journals and Discussion Forums are required to submit in the Interact2, unless your lecturer advises otherwise.
Please submit the assignments only as word document in Turnitin, unless your lecturer advises otherwise .
Assignment/s must be submitted through Turnitin by midnight (AEST) according to the date mentioned in the subject outline.
Assignments submitted in the RESPECTIVE FINAL FOLDER only will be considered for marking.
Postal Submission
Under normal circumstances postal submissions will not be accepted for any of the assessments required.
Hand Delivered Submission
Under normal circumstances hand delivered submissions will not be accepted for any of the assessments required.
Assignment Return
You should normally expect your marked assignment to be returned to you within 15 working days of the due date. If you submitted your assignment on time but have not returned by the return date, you should make enquiries in the first instance to the subject lecturer. If the subject lecturer is not available then contact your Course Coordinator on Level 4, 30 Church Lane.
Student Feedback and Learning Analytics
Evaluation of Subjects
CSU values constructive feedback and relies on high response rates to Subject Experience Surveys (SES) to enhance teaching. Responses are fed back anonymously to Subject Coordinators and Heads of Schools to form the basis for subject enhancement and recognition of excellence in teaching. Schools report on their evaluation data; highlighting good practice and documenting how problems have been addressed. You can view a summary of survey results via the Student Portal
We strongly encourage you to complete your online Subject Experience Surveys. You will be provided with links to your surveys via email when they open three [3] weeks before the end of session.
Changes and actions based on previous student feedback
Update topics to match the refereed exercise number with the current textbook
Reschedule content in such a way that students get enough time to complete their assignments.
Change assignments so that students can understand what exactly is required to complete.
Learning analytics in this subject
Learning Analytics refers to the collection and analysis of student data for the purpose of improving learning and teaching. It enables the University to personalise the support we provide our students. All Learning Analytics activities will take place in accordance with the CSU Learning Analytics Code of Practice. For more information, please visit CSU’s website.
Data about your activity in the Interact2 site and other learning technologies for this subject will be recorded and can be reviewed by teaching staff to inform their communication, support and teaching practices.
Based on past analytics, changes made to the subject included <ABC> and <XYZ>.
Services and Support
Your Service Portal tells you how you can seek services and support. These include study, admin, residential, library, careers, financial, and personal support.
Develop your study skills
Devlop your study skills with our free study services. We have services online, on campus and near you. These services can help you develop your English language, literacy, and numeracy.
Library Services
provides access to the eBooks, journal articles, books, and multimedia resources needed for your studies and assessments. Get the most out of these resources by contacting Library staff either online or in person, or make use of the many Library Resource Guides, videos and online workshops available.
CSU Policies and Regulations
This subject outline should be read in conjunction with all academic policies and regulations, e.g. Student Academic Misconduct Policy, Assessment Policy – Coursework Subjects, Assessment Principles Policy, Special Consideration Policy, Academic Progress Policy, Academic Communication with Students Policy, Student Charter, etc.
Subject Outline as a Reference Document
This Subject Outline is an accurate and historical record of the curriculum and scope of your subject. CSU's requires that you retain a copy of the Subject Outline for future use such as for accreditation purposes.
Order Now
0 notes
sandeep94674-blog · 7 years ago
Text
ITC538 | FINAL EXAM JAVA
New Post has been published on https://punjabassignmenthelp.com/itc538-final-exam-java/
ITC538 | FINAL EXAM JAVA
ITC538 | FINAL EXAM JAVA| JAVA
JAVA ASSIGNMENT HELP
Rationale
To assess students’ understanding of the fundamental concepts of the subject material; their ability to integrate and apply information from various topics; and to apply their understanding and knowledge to simple problems.
Requirements
You are required to sit and pass the final exam in this subject to be eligible for a passing grade. The exam is worth 50% of the marks in this subject and you are required to answer following number of questions:
30 multiple-choice questions worth 45 marks
3 short-answer questions worth 25 marks each
Number of marks:  120 marks
The final exam will cover all the subject’s topics.
SAMPLE EXAMINATION
INSTRUCTIONS TO CANDIDATES:
Enter your name, student number and signature into the box below.
Attempt ALL questions.
Start a new page for each new question, but NOT for each part of a question.
Read each question carefully to ensure that you have answered everything that is required in the question. Most questions have multiple parts.
There are 120 possible marks for this examination.
This examination is worth 50% of the final assessment for this subject.
  INSTRUCTIONS TO INVIGILATORS:
Question paper May not be retained by the candidate
PART A – Multiple-choice Questions (Total Marks 45)
In this part there are 30 questions each worth 1.5marks.
Select what you consider to be the correct answer for each question and mark it on the supplied answer sheet using a lead pencil.
Make sure that you put your name and student number on the answer sheet. The question sheet and the answer sheet are to be returned with the rest of the examination paper.
A full sample of multiple choice questions is not available for release. The following questions provide an indication of the style of multiple choice questions.
What of the following is a valid identifier?
radius
8+9
class
$343
What is output by the following code?
int x = 2, y = 5;
if ((x < 5) && (y != 5))
System.out.println(x/y);
else if ((x > 3) || (y < 10))
System.out.println(x – y);
else
System.out.println(x + y);
0
1
7
-3
Analyse the following code.
boolean even = ((231 % 2) == 0);
if (even == true)
System.out.println(“It is even!”);
else
System.out.println(“It is odd!”);
Which of the following is true?
The program has a syntax error
The program displays “It is even!”
The program has a run-time error
The program displays “It is odd!”
What is y after the following switch statement?
int x = 0;
int y = 2;
switch (x + 1)
case 0: y = 0;
case 1: y = 1;
default: y = -1;
2
0
1
-1
What is output by the following code? int x = 1, y = 2;
while (x <= 11)
y += 2;
x += y
System.out.print(x + ” ” + y + ” “);
5 4 6 11
5 4 11 6 19 8
4 5 6 11
3 4 10 8 19
What is output by the following code?
for (int i=0; i < 5; ++i)
System.out.print(i*2 + “, “);
0, 1, 2, 3, 4,
0, 2, 4, 6,
0, 2, 4, 6, 8,
2, 4, 6, 8, 10,
What is the effect of the following code?
int balance = 10;
while (balance > =1)
if (balance < 9) break;
balance = balance – 9;
After the code, balance has the value 1
After the code, balance has the value 10
After the code, balance has the value -1
After the code, balance has the value 2
The header of a method is specified as: int func(double x)
Which of the following expressions or statements contains an illegal method call?
return func(2);
func(1+2.2)
func(func(2.5))
out.print(func());
What is the output by the following code?
char ch1 = ‘A’;
System.out.println(ch1 + ” + 4 is ” + (ch1 + 4));
A + 4 is E
A + 4 is 69
A + 4 is A4
A + 4 is 654
The variable tax has been declared of type double and has the value 19.257. For the expression (int)(tax*100)/100.0
which of the following is true?
It is illegal
Its value is 19
Its value is 19.25
Its value is 0.0
A programmer has written the following method to swap the values of two arguments passed to it.
static void swap(int x, int y)
int temp = x;
x = y;
y = temp;
Which of the following is true for this method?
It will cause a compilation error
It will compile and execute as intended
It will cause a run-time error
It will cause a logic error
A programmer has written a hypotenuse method, which is used as follows:
int x = 3, y = 6;
double length = hypotenuse(x, y);
The header for the hypotenuse method is:
void hypotenuse(x, y)
double hypotenuse(a, b)
void hypotenuse(int x, int y)
double hypotenuse(int a, int b)
Overloading in Java allows:
methods in a class to have the same name but different parameter lists
variables in different methods to have the same name
methods inherited from a superclass to be modified
a memory location to be used for different variables at different times
The keyword used to make a variable belong to a class, rather than to each instance of a class is:
import
class
static
final
A programmer has written a method named fillIt to initialise the elements of an array of integers.
The programmer uses the method as follows:
int[] numbers = new int[20];
fillIt(numbers);
Which of the following is true?
The array object must be constructed inside the method, not outside it
The elements of an array cannot be initialised using a method
The design is correct
If the array object is constructed outside the method, a reference must be returned
  PART B – Short-Answer Questions (Total Marks 75)
In answering the questions in this part, you may assume the existence of any standard data entry classes you typically use, such as Scanner.
Question 1 (25 marks)
(a) (Computing x) Approximate the value of a quantity x using the following series:
x = 1 + 1/2 + 1/3 + 1/4+….+1/n where n is a positive integer. The value of n should be passed to the
method.
Write a java method that calculates and displays the value of x for n (for example n = 1000). [7 marks]
(Area of regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is
where n is the number of sides and s is the side of the polygon.
Write a Java method that returns the area of a regular polygon using the following header:
public static double area(int n, double side).
(Hints: You may need Math.tan() function and Math.PI for area calculations.)
[9 marks]
(c) (Rectangle class) Design a class to represent a rectangle. The class is specified as follows:
Two double data fields named width and height hold the width and height of the rectangle. The default values are 1 for both width and height.
A no-arg constructor creates a default rectangle.
Getter and setter methods are provided for all data fields.
Accessor methods return the area and the perimeter.         [9 marks]
Question 2 (25 marks)
(a) Write the code for an Employee class, which has the following fields:
private String name;
private double salary;
Your class should contain the following:
Provide a constructor to set the employee’s name using a passed argument and also to set the salary to $0.
Provide a constructor that accepts arguments to set the employee’s name and salary. The salary should be set using the mutator method for salary described below.
Provide a mutator (i.e. setter) method for the salary that ensures the salary remains within the inclusive range $0 to $100,000. If an attempt is made to set a salary outside this range the current salary will not be changed.
Provide accessor (i.e. getter) methods for the name and for the salary. (15 marks)
(b) Write a program, called TestEmployee.java, to do the following:
Create an employee object referenced by emp1, using the name “Fred”.
Assign a salary of $45,000 for employee “Fred”.
Create an employee object referenced by emp2, using the name “Sue” and assigns her a salary of $55,000, all in the one statement.
On a separate line for each employee, display the employee’s name and 40% of the salary, for taxation purposes. (10 marks)
Question 3 (25 marks)
The following incomplete WordList class is intended as a collection class for holding a list of words.
class WordList
private static final int DEFAULTSIZE = 100;
private int maxWords;
private String[] list;
private int length;
Here the constant provides a default value to replace any request for an illegal array size, the array provides a place to store the words, maxWords will record the size of the array, and length will record how many words are currently stored in it.
Write a constructer for WordList that accepts a parameter for the size of the array. The constructor will create an array for the words of the requested size, or of the default size if the size requested is not appropriate. It will also record the size of the array and set the current length appropriately. (5 marks)
Write a method addWord to add a word to the array. This will accept a String reference and return a Boolean value indicating whether or not the word in the String was able to be added. It should update the state of the collection object as appropriate. Note that a String object is immutable and can be added safely to the collection without needing to be copied. (10 marks)
Write a method findWord to find the first occurrence in the collection of a word beginning with a specified prefix. This method will accept a reference to a String object containing the prefix and return a String reference to the word found, or null if there is no matching word. The String class contains a startsWith instance method, which accepts a String argument and returns a boolean indicating whether the instance string starts with the argument string. (10 marks)
Material provided by the University
1 x 12pp Answer Booklet
General Purpose Answer Sheet
Material required by the student
Writing implements
2B Pencil and Eraser
Assessment Information
Learning materials
How to apply for special consideration
Academic regulations provide for special consideration to be given if you suffer misadventure or extenuating circumstances during the session (including the examination period) which prevents you from meeting acceptable standards or deadlines. Find the form on the Student Portal page.
Extensions
In order to ensure that students who hand their assignments in on time are not disadvantaged, and to enable me to comply with the requirement to return assignments to the class within 15 working days, the following rules about extensions will be strictly enforced:
Extensions cannot be granted for online tests, as these have to be done within a specific time frame, after which the answers are released to the class automatically.
Computer problems (such as the speed of your computer and the time it may take you to upload assignments onto TURNITIN) and normal work-related pressures and family commitments do not constitute sufficient reasons for the granting of extensions.
If it becomes obvious that you are not going to be able to submit an assignment on time because of an unavoidable problem, you must submit your request for an extension, prior to the due date, either by writing (email is acceptable) to your lecturer/subject coordinator or via the Request for Special Consideration form.
You are encouraged to make requests via email (especially for urgent requests), since the processing time for applications made through the online form can be a few days. Requests for extensions will not be granted on or after the due date so you must make sure that any extension is requested prior to the day on which the assignment is due.
You are expected to do all you can to meet assignment deadlines. Work and family- related pressures do not normally constitute sufficient reasons for the granting of extensions or incomplete grades.
If you apply for an extension, you may be asked to email your lecturer/subject coodinator on what you have done so far on the assignment.
You must be able to provide documentary evidence (such as a certificate from a doctor or counsellor) justifying the need for an extension as soon as practicable – but please note that if the circumstances giving rise to the request for an extension arise on a day when you cannot get documentary evidence, you must still apply for the extension before the due date and submit the documentary evidence afterwards.
Given the tight deadlines involved in returning assignments to students and putting feedback on Interact, the maximum extension granted generally will be seven (7) days from the due date.
Assignments received more than 10 days after the due date or extension date will not be marked unless the staff member decides otherwise. Items received late will be penalised at 10% of the mark available for the assessment item per day it is late (see below).
Note that for purposes of measuring lateness, the ‘day’ begins just after 00.00 hrs AEST – so an assignment received after midnight of the due date will be penalised 10% for lateness. This rule will be applied to all students uniformly.
Penalties for Late Submission
The Faculty of Business has determined that the penalty for the late submission of an assessment task (without obtaining the Subject Coordinator’s approval for an extension) will be:
10% deduction per day, including weekends, of the maximum marks allocated for the assessment task, i.e. 1 day late 10% deduction, or 2 days late 20% deduction.
An example of the calculation would be:
Maximum marks allocated = 20
Penalty for one day late = 2 marks (so, a score of 18/20 becomes 16/20 and a score of 12/20 becomes 10/20).
If an assignment is due on a Friday but is not submitted until the following Tuesday, then the penalty will be four days (40% deduction or 8 marks in the example above).
Submissions more than 10 days late will be acknowledged as received but will not be marked.
Resubmission
Under normal circumstances resubmission of assessment items will not be accepted for any of the assessments required in this subject.
Online Submission
Assignments should be submitted through TurnItIn. Please meet with your respective lecturer to enroll in the Turnitin (If you do not receive any email from Turnitin for this subject).
Assessments such as Blogs, Quizzes, Journals and Discussion Forums are required to submit in the Interact2, unless your lecturer advises otherwise.
Please submit the assignments only as word document in Turnitin, unless your lecturer advises otherwise .
Assignment/s must be submitted through Turnitin by midnight (AEST) according to the date mentioned in the subject outline.
Assignments submitted in the RESPECTIVE FINAL FOLDER only will be considered for marking.
Postal Submission
Under normal circumstances postal submissions will not be accepted for any of the assessments required.
Hand Delivered Submission
Under normal circumstances hand delivered submissions will not be accepted for any of the assessments required.
Assignment Return
You should normally expect your marked assignment to be returned to you within 15 working days of the due date. If you submitted your assignment on time but have not returned by the return date, you should make enquiries in the first instance to the subject lecturer. If the subject lecturer is not available then contact your Course Coordinator on Level 4, 30 Church Lane.
Student Feedback and Learning Analytics
Evaluation of Subjects
CSU values constructive feedback and relies on high response rates to Subject Experience Surveys (SES) to enhance teaching. Responses are fed back anonymously to Subject Coordinators and Heads of Schools to form the basis for subject enhancement and recognition of excellence in teaching. Schools report on their evaluation data; highlighting good practice and documenting how problems have been addressed. You can view a summary of survey results via the Student Portal
We strongly encourage you to complete your online Subject Experience Surveys. You will be provided with links to your surveys via email when they open three [3] weeks before the end of session.
Changes and actions based on previous student feedback
Update topics to match the refereed exercise number with the current textbook
Reschedule content in such a way that students get enough time to complete their assignments.
Change assignments so that students can understand what exactly is required to complete.
Learning analytics in this subject
Learning Analytics refers to the collection and analysis of student data for the purpose of improving learning and teaching. It enables the University to personalise the support we provide our students. All Learning Analytics activities will take place in accordance with the CSU Learning Analytics Code of Practice. For more information, please visit CSU’s website.
Data about your activity in the Interact2 site and other learning technologies for this subject will be recorded and can be reviewed by teaching staff to inform their communication, support and teaching practices.
Based on past analytics, changes made to the subject included <ABC> and <XYZ>.
Services and Support
Your Service Portal tells you how you can seek services and support. These include study, admin, residential, library, careers, financial, and personal support.
Develop your study skills
Devlop your study skills with our free study services. We have services online, on campus and near you. These services can help you develop your English language, literacy, and numeracy.
Library Services
provides access to the eBooks, journal articles, books, and multimedia resources needed for your studies and assessments. Get the most out of these resources by contacting Library staff either online or in person, or make use of the many Library Resource Guides, videos and online workshops available.
CSU Policies and Regulations
This subject outline should be read in conjunction with all academic policies and regulations, e.g. Student Academic Misconduct Policy, Assessment Policy – Coursework Subjects, Assessment Principles Policy, Special Consideration Policy, Academic Progress Policy, Academic Communication with Students Policy, Student Charter, etc.
Subject Outline as a Reference Document
This Subject Outline is an accurate and historical record of the curriculum and scope of your subject. CSU’s requires that you retain a copy of the Subject Outline for future use such as for accreditation purposes.
Punjab Assignment Help
Buy Online Assignment Help services for COMPUTER ASSIGNMENT with Punjab Assignment Help at [email protected]
0 notes
jasveerkaur94674-blog · 7 years ago
Text
ITC538 | FINAL EXAM JAVA
New Post has been published on https://punjabassignmenthelp.com/itc538-final-exam-java/
ITC538 | FINAL EXAM JAVA
ITC538 | FINAL EXAM JAVA| JAVA
JAVA ASSIGNMENT HELP
Rationale
To assess students’ understanding of the fundamental concepts of the subject material; their ability to integrate and apply information from various topics; and to apply their understanding and knowledge to simple problems.
Requirements
You are required to sit and pass the final exam in this subject to be eligible for a passing grade. The exam is worth 50% of the marks in this subject and you are required to answer following number of questions:
30 multiple-choice questions worth 45 marks
3 short-answer questions worth 25 marks each
Number of marks:  120 marks
The final exam will cover all the subject’s topics.
SAMPLE EXAMINATION
INSTRUCTIONS TO CANDIDATES:
Enter your name, student number and signature into the box below.
Attempt ALL questions.
Start a new page for each new question, but NOT for each part of a question.
Read each question carefully to ensure that you have answered everything that is required in the question. Most questions have multiple parts.
There are 120 possible marks for this examination.
This examination is worth 50% of the final assessment for this subject.
  INSTRUCTIONS TO INVIGILATORS:
Question paper May not be retained by the candidate
PART A – Multiple-choice Questions (Total Marks 45)
In this part there are 30 questions each worth 1.5marks.
Select what you consider to be the correct answer for each question and mark it on the supplied answer sheet using a lead pencil.
Make sure that you put your name and student number on the answer sheet. The question sheet and the answer sheet are to be returned with the rest of the examination paper.
A full sample of multiple choice questions is not available for release. The following questions provide an indication of the style of multiple choice questions.
What of the following is a valid identifier?
radius
8+9
class
$343
What is output by the following code?
int x = 2, y = 5;
if ((x < 5) && (y != 5))
System.out.println(x/y);
else if ((x > 3) || (y < 10))
System.out.println(x – y);
else
System.out.println(x + y);
0
1
7
-3
Analyse the following code.
boolean even = ((231 % 2) == 0);
if (even == true)
System.out.println(“It is even!”);
else
System.out.println(“It is odd!”);
Which of the following is true?
The program has a syntax error
The program displays “It is even!”
The program has a run-time error
The program displays “It is odd!”
What is y after the following switch statement?
int x = 0;
int y = 2;
switch (x + 1)
case 0: y = 0;
case 1: y = 1;
default: y = -1;
2
0
1
-1
What is output by the following code? int x = 1, y = 2;
while (x <= 11)
y += 2;
x += y
System.out.print(x + ” ” + y + ” “);
5 4 6 11
5 4 11 6 19 8
4 5 6 11
3 4 10 8 19
What is output by the following code?
for (int i=0; i < 5; ++i)
System.out.print(i*2 + “, “);
0, 1, 2, 3, 4,
0, 2, 4, 6,
0, 2, 4, 6, 8,
2, 4, 6, 8, 10,
What is the effect of the following code?
int balance = 10;
while (balance > =1)
if (balance < 9) break;
balance = balance – 9;
After the code, balance has the value 1
After the code, balance has the value 10
After the code, balance has the value -1
After the code, balance has the value 2
The header of a method is specified as: int func(double x)
Which of the following expressions or statements contains an illegal method call?
return func(2);
func(1+2.2)
func(func(2.5))
out.print(func());
What is the output by the following code?
char ch1 = ‘A’;
System.out.println(ch1 + ” + 4 is ” + (ch1 + 4));
A + 4 is E
A + 4 is 69
A + 4 is A4
A + 4 is 654
The variable tax has been declared of type double and has the value 19.257. For the expression (int)(tax*100)/100.0
which of the following is true?
It is illegal
Its value is 19
Its value is 19.25
Its value is 0.0
A programmer has written the following method to swap the values of two arguments passed to it.
static void swap(int x, int y)
int temp = x;
x = y;
y = temp;
Which of the following is true for this method?
It will cause a compilation error
It will compile and execute as intended
It will cause a run-time error
It will cause a logic error
A programmer has written a hypotenuse method, which is used as follows:
int x = 3, y = 6;
double length = hypotenuse(x, y);
The header for the hypotenuse method is:
void hypotenuse(x, y)
double hypotenuse(a, b)
void hypotenuse(int x, int y)
double hypotenuse(int a, int b)
Overloading in Java allows:
methods in a class to have the same name but different parameter lists
variables in different methods to have the same name
methods inherited from a superclass to be modified
a memory location to be used for different variables at different times
The keyword used to make a variable belong to a class, rather than to each instance of a class is:
import
class
static
final
A programmer has written a method named fillIt to initialise the elements of an array of integers.
The programmer uses the method as follows:
int[] numbers = new int[20];
fillIt(numbers);
Which of the following is true?
The array object must be constructed inside the method, not outside it
The elements of an array cannot be initialised using a method
The design is correct
If the array object is constructed outside the method, a reference must be returned
  PART B – Short-Answer Questions (Total Marks 75)
In answering the questions in this part, you may assume the existence of any standard data entry classes you typically use, such as Scanner.
Question 1 (25 marks)
(a) (Computing x) Approximate the value of a quantity x using the following series:
x = 1 + 1/2 + 1/3 + 1/4+….+1/n where n is a positive integer. The value of n should be passed to the
method.
Write a java method that calculates and displays the value of x for n (for example n = 1000). [7 marks]
(Area of regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is
where n is the number of sides and s is the side of the polygon.
Write a Java method that returns the area of a regular polygon using the following header:
public static double area(int n, double side).
(Hints: You may need Math.tan() function and Math.PI for area calculations.)
[9 marks]
(c) (Rectangle class) Design a class to represent a rectangle. The class is specified as follows:
Two double data fields named width and height hold the width and height of the rectangle. The default values are 1 for both width and height.
A no-arg constructor creates a default rectangle.
Getter and setter methods are provided for all data fields.
Accessor methods return the area and the perimeter.         [9 marks]
Question 2 (25 marks)
(a) Write the code for an Employee class, which has the following fields:
private String name;
private double salary;
Your class should contain the following:
Provide a constructor to set the employee’s name using a passed argument and also to set the salary to $0.
Provide a constructor that accepts arguments to set the employee’s name and salary. The salary should be set using the mutator method for salary described below.
Provide a mutator (i.e. setter) method for the salary that ensures the salary remains within the inclusive range $0 to $100,000. If an attempt is made to set a salary outside this range the current salary will not be changed.
Provide accessor (i.e. getter) methods for the name and for the salary. (15 marks)
(b) Write a program, called TestEmployee.java, to do the following:
Create an employee object referenced by emp1, using the name “Fred”.
Assign a salary of $45,000 for employee “Fred”.
Create an employee object referenced by emp2, using the name “Sue” and assigns her a salary of $55,000, all in the one statement.
On a separate line for each employee, display the employee’s name and 40% of the salary, for taxation purposes. (10 marks)
Question 3 (25 marks)
The following incomplete WordList class is intended as a collection class for holding a list of words.
class WordList
private static final int DEFAULTSIZE = 100;
private int maxWords;
private String[] list;
private int length;
Here the constant provides a default value to replace any request for an illegal array size, the array provides a place to store the words, maxWords will record the size of the array, and length will record how many words are currently stored in it.
Write a constructer for WordList that accepts a parameter for the size of the array. The constructor will create an array for the words of the requested size, or of the default size if the size requested is not appropriate. It will also record the size of the array and set the current length appropriately. (5 marks)
Write a method addWord to add a word to the array. This will accept a String reference and return a Boolean value indicating whether or not the word in the String was able to be added. It should update the state of the collection object as appropriate. Note that a String object is immutable and can be added safely to the collection without needing to be copied. (10 marks)
Write a method findWord to find the first occurrence in the collection of a word beginning with a specified prefix. This method will accept a reference to a String object containing the prefix and return a String reference to the word found, or null if there is no matching word. The String class contains a startsWith instance method, which accepts a String argument and returns a boolean indicating whether the instance string starts with the argument string. (10 marks)
Material provided by the University
1 x 12pp Answer Booklet
General Purpose Answer Sheet
Material required by the student
Writing implements
2B Pencil and Eraser
Assessment Information
Learning materials
How to apply for special consideration
Academic regulations provide for special consideration to be given if you suffer misadventure or extenuating circumstances during the session (including the examination period) which prevents you from meeting acceptable standards or deadlines. Find the form on the Student Portal page.
Extensions
In order to ensure that students who hand their assignments in on time are not disadvantaged, and to enable me to comply with the requirement to return assignments to the class within 15 working days, the following rules about extensions will be strictly enforced:
Extensions cannot be granted for online tests, as these have to be done within a specific time frame, after which the answers are released to the class automatically.
Computer problems (such as the speed of your computer and the time it may take you to upload assignments onto TURNITIN) and normal work-related pressures and family commitments do not constitute sufficient reasons for the granting of extensions.
If it becomes obvious that you are not going to be able to submit an assignment on time because of an unavoidable problem, you must submit your request for an extension, prior to the due date, either by writing (email is acceptable) to your lecturer/subject coordinator or via the Request for Special Consideration form.
You are encouraged to make requests via email (especially for urgent requests), since the processing time for applications made through the online form can be a few days. Requests for extensions will not be granted on or after the due date so you must make sure that any extension is requested prior to the day on which the assignment is due.
You are expected to do all you can to meet assignment deadlines. Work and family- related pressures do not normally constitute sufficient reasons for the granting of extensions or incomplete grades.
If you apply for an extension, you may be asked to email your lecturer/subject coodinator on what you have done so far on the assignment.
You must be able to provide documentary evidence (such as a certificate from a doctor or counsellor) justifying the need for an extension as soon as practicable – but please note that if the circumstances giving rise to the request for an extension arise on a day when you cannot get documentary evidence, you must still apply for the extension before the due date and submit the documentary evidence afterwards.
Given the tight deadlines involved in returning assignments to students and putting feedback on Interact, the maximum extension granted generally will be seven (7) days from the due date.
Assignments received more than 10 days after the due date or extension date will not be marked unless the staff member decides otherwise. Items received late will be penalised at 10% of the mark available for the assessment item per day it is late (see below).
Note that for purposes of measuring lateness, the ‘day’ begins just after 00.00 hrs AEST – so an assignment received after midnight of the due date will be penalised 10% for lateness. This rule will be applied to all students uniformly.
Penalties for Late Submission
The Faculty of Business has determined that the penalty for the late submission of an assessment task (without obtaining the Subject Coordinator’s approval for an extension) will be:
10% deduction per day, including weekends, of the maximum marks allocated for the assessment task, i.e. 1 day late 10% deduction, or 2 days late 20% deduction.
An example of the calculation would be:
Maximum marks allocated = 20
Penalty for one day late = 2 marks (so, a score of 18/20 becomes 16/20 and a score of 12/20 becomes 10/20).
If an assignment is due on a Friday but is not submitted until the following Tuesday, then the penalty will be four days (40% deduction or 8 marks in the example above).
Submissions more than 10 days late will be acknowledged as received but will not be marked.
Resubmission
Under normal circumstances resubmission of assessment items will not be accepted for any of the assessments required in this subject.
Online Submission
Assignments should be submitted through TurnItIn. Please meet with your respective lecturer to enroll in the Turnitin (If you do not receive any email from Turnitin for this subject).
Assessments such as Blogs, Quizzes, Journals and Discussion Forums are required to submit in the Interact2, unless your lecturer advises otherwise.
Please submit the assignments only as word document in Turnitin, unless your lecturer advises otherwise .
Assignment/s must be submitted through Turnitin by midnight (AEST) according to the date mentioned in the subject outline.
Assignments submitted in the RESPECTIVE FINAL FOLDER only will be considered for marking.
Postal Submission
Under normal circumstances postal submissions will not be accepted for any of the assessments required.
Hand Delivered Submission
Under normal circumstances hand delivered submissions will not be accepted for any of the assessments required.
Assignment Return
You should normally expect your marked assignment to be returned to you within 15 working days of the due date. If you submitted your assignment on time but have not returned by the return date, you should make enquiries in the first instance to the subject lecturer. If the subject lecturer is not available then contact your Course Coordinator on Level 4, 30 Church Lane.
Student Feedback and Learning Analytics
Evaluation of Subjects
CSU values constructive feedback and relies on high response rates to Subject Experience Surveys (SES) to enhance teaching. Responses are fed back anonymously to Subject Coordinators and Heads of Schools to form the basis for subject enhancement and recognition of excellence in teaching. Schools report on their evaluation data; highlighting good practice and documenting how problems have been addressed. You can view a summary of survey results via the Student Portal
We strongly encourage you to complete your online Subject Experience Surveys. You will be provided with links to your surveys via email when they open three [3] weeks before the end of session.
Changes and actions based on previous student feedback
Update topics to match the refereed exercise number with the current textbook
Reschedule content in such a way that students get enough time to complete their assignments.
Change assignments so that students can understand what exactly is required to complete.
Learning analytics in this subject
Learning Analytics refers to the collection and analysis of student data for the purpose of improving learning and teaching. It enables the University to personalise the support we provide our students. All Learning Analytics activities will take place in accordance with the CSU Learning Analytics Code of Practice. For more information, please visit CSU’s website.
Data about your activity in the Interact2 site and other learning technologies for this subject will be recorded and can be reviewed by teaching staff to inform their communication, support and teaching practices.
Based on past analytics, changes made to the subject included <ABC> and <XYZ>.
Services and Support
Your Service Portal tells you how you can seek services and support. These include study, admin, residential, library, careers, financial, and personal support.
Develop your study skills
Devlop your study skills with our free study services. We have services online, on campus and near you. These services can help you develop your English language, literacy, and numeracy.
Library Services
provides access to the eBooks, journal articles, books, and multimedia resources needed for your studies and assessments. Get the most out of these resources by contacting Library staff either online or in person, or make use of the many Library Resource Guides, videos and online workshops available.
CSU Policies and Regulations
This subject outline should be read in conjunction with all academic policies and regulations, e.g. Student Academic Misconduct Policy, Assessment Policy – Coursework Subjects, Assessment Principles Policy, Special Consideration Policy, Academic Progress Policy, Academic Communication with Students Policy, Student Charter, etc.
Subject Outline as a Reference Document
This Subject Outline is an accurate and historical record of the curriculum and scope of your subject. CSU’s requires that you retain a copy of the Subject Outline for future use such as for accreditation purposes.
Punjab Assignment Help
Buy Online Assignment Help services for COMPUTER ASSIGNMENT with Punjab Assignment Help at [email protected]
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:               service_time  =  (tally_time  x  efficiency)  +  payment_time            where:                   tally_time:  time it takes to tally up the customer's goods                   efficiency:  the efficiency of the server                  payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue
Tumblr media
Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.
Tumblr media
Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()             Declare variables and instances and do initialisations             Open the input data file;  if not found print error and exit           Read first CustomerArrival event from file and add it to the event queue      While the event queue is not empty . . .                        Get the next event from the event queue and set CrntTime to the event time                            If the event type = CustomerArrival event . . .                                            if an idle server is available . . .                                                    Find fastest idle serve                                                      set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                   add ServerFinish event to the event queue                                  Else                                           Add event's customer to the customer queue                                  End if                                  If not EOF . . .                                                    Read next customer arrival from file                                        add CustomerArrival event to the event queue                                  End if                        Else // event type must be a ServerFinish event . . .                                      Get server no. from event, set server to idle and do server's stats                               If customer queue is not empty . . .                                                    Get next customer from the customer queue                                                  Find fastest idle serve                                                     set the server’s idle flag to busy.                                            calculate the server’s finish time                                                add ServerFinish event to the event queue                                  End if                       End if            End while             Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java: javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.  
Marking Guide
Marks will be awarded for the appropriate use of data structures and the efficiency of the program at processing the input and producing the correct output. Marks may be deducted for untidy or poorly designed code. Appropriate comments should be provided where needed. There will be a deduction of up to 4 marks for using STL, or equivalent libraries, rather than coding the data structures and algorithms yourself. You may use string or String type for storing words or text, if you wish. All coding and comments must be your own work.   Submission: Assignments should be typed into a single text file named "ass2.ext" where "ext" is the appropriate file extension for the chosen language. You should run your program and copy and paste the output into a text file named: "output.txt"   Submit your files via the submit program on banshee:                  submit -u user -c csci203 -a 2 ass1.ext output.txt      - where user is your unix userid and ext is the extn of your code file. Late assignment submissions without granted extension will be marked but the points awarded will be reduced by 1 mark for each day late.  Assignments will not be accepted if more than five days late. An extension of time for the assignment submission may be granted in certain circumstances.  Any request for an extension of the submission deadline must be made via SOLS before the submission deadline. Supporting documentation should accompany the request for any extension. Read the full article
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:               service_time  =  (tally_time  x  efficiency)  +  payment_time            where:                   tally_time:  time it takes to tally up the customer's goods                   efficiency:  the efficiency of the server                  payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue
Tumblr media
Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.
Tumblr media
Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()             Declare variables and instances and do initialisations             Open the input data file;  if not found print error and exit           Read first CustomerArrival event from file and add it to the event queue      While the event queue is not empty . . .                        Get the next event from the event queue and set CrntTime to the event time                            If the event type = CustomerArrival event . . .                                            if an idle server is available . . .                                                    Find fastest idle serve                                                      set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                   add ServerFinish event to the event queue                                  Else                                           Add event's customer to the customer queue    ��                             End if                                  If not EOF . . .                                                    Read next customer arrival from file                                        add CustomerArrival event to the event queue                                  End if                        Else // event type must be a ServerFinish event . . .                                      Get server no. from event, set server to idle and do server's stats                               If customer queue is not empty . . .                                                    Get next customer from the customer queue                                                  Find fastest idle serve                                                     set the server’s idle flag to busy.                                            calculate the server’s finish time                                                add ServerFinish event to the event queue                                  End if                       End if            End while             Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java: javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.  
Marking Guide
Marks will be awarded for the appropriate use of data structures and the efficiency of the program at processing the input and producing the correct output. Marks may be deducted for untidy or poorly designed code. Appropriate comments should be provided where needed. There will be a deduction of up to 4 marks for using STL, or equivalent libraries, rather than coding the data structures and algorithms yourself. You may use string or String type for storing words or text, if you wish. All coding and comments must be your own work.   Submission: Assignments should be typed into a single text file named "ass2.ext" where "ext" is the appropriate file extension for the chosen language. You should run your program and copy and paste the output into a text file named: "output.txt"   Submit your files via the submit program on banshee:                  submit -u user -c csci203 -a 2 ass1.ext output.txt      - where user is your unix userid and ext is the extn of your code file. Late assignment submissions without granted extension will be marked but the points awarded will be reduced by 1 mark for each day late.  Assignments will not be accepted if more than five days late. An extension of time for the assignment submission may be granted in certain circumstances.  Any request for an extension of the submission deadline must be made via SOLS before the submission deadline. Supporting documentation should accompany the request for any extension. Read the full article
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:               service_time  =  (tally_time  x  efficiency)  +  payment_time            where:                   tally_time:  time it takes to tally up the customer's goods                   efficiency:  the efficiency of the server                  payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue
Tumblr media
Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.
Tumblr media
Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()             Declare variables and instances and do initialisations             Open the input data file;  if not found print error and exit           Read first CustomerArrival event from file and add it to the event queue      While the event queue is not empty . . .                        Get the next event from the event queue and set CrntTime to the event time                            If the event type = CustomerArrival event . . .                                            if an idle server is available . . .                                                    Find fastest idle serve                                                      set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                   add ServerFinish event to the event queue                                  Else                                           Add event's customer to the customer queue                                  End if                                  If not EOF . . .                                                    Read next customer arrival from file                                        add CustomerArrival event to the event queue                                  End if                        Else // event type must be a ServerFinish event . . .                                      Get server no. from event, set server to idle and do server's stats                               If customer queue is not empty . . .                                                    Get next customer from the customer queue                                                  Find fastest idle serve                                                     set the server’s idle flag to busy.                                            calculate the server’s finish time                                                add ServerFinish event to the event queue                                  End if                       End if            End while             Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java: javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.  
Marking Guide
Marks will be awarded for the appropriate use of data structures and the efficiency of the program at processing the input and producing the correct output. Marks may be deducted for untidy or poorly designed code. Appropriate comments should be provided where needed. There will be a deduction of up to 4 marks for using STL, or equivalent libraries, rather than coding the data structures and algorithms yourself. You may use string or String type for storing words or text, if you wish. All coding and comments must be your own work.   Submission: Assignments should be typed into a single text file named "ass2.ext" where "ext" is the appropriate file extension for the chosen language. You should run your program and copy and paste the output into a text file named: "output.txt"   Submit your files via the submit program on banshee:                  submit -u user -c csci203 -a 2 ass1.ext output.txt      - where user is your unix userid and ext is the extn of your code file. Late assignment submissions without granted extension will be marked but the points awarded will be reduced by 1 mark for each day late.  Assignments will not be accepted if more than five days late. An extension of time for the assignment submission may be granted in certain circumstances.  Any request for an extension of the submission deadline must be made via SOLS before the submission deadline. Supporting documentation should accompany the request for any extension. Read the full article
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:               service_time  =  (tally_time  x  efficiency)  +  payment_time            where:                   tally_time:  time it takes to tally up the customer's goods                   efficiency:  the efficiency of the server                  payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue
Tumblr media
Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.
Tumblr media
Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()             Declare variables and instances and do initialisations             Open the input data file;  if not found print error and exit           Read first CustomerArrival event from file and add it to the event queue      While the event queue is not empty . . .                  ��     Get the next event from the event queue and set CrntTime to the event time                            If the event type = CustomerArrival event . . .                                            if an idle server is available . . .                                                    Find fastest idle serve                                                      set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                   add ServerFinish event to the event queue                                  Else                                           Add event's customer to the customer queue                                  End if                                  If not EOF . . .                                                    Read next customer arrival from file                                        add CustomerArrival event to the event queue                                  End if                        Else // event type must be a ServerFinish event . . .                                      Get server no. from event, set server to idle and do server's stats                               If customer queue is not empty . . .                                                    Get next customer from the customer queue                                                  Find fastest idle serve                                                     set the server’s idle flag to busy.                                            calculate the server’s finish time                                                add ServerFinish event to the event queue                                  End if                       End if            End while             Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java: javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.  
Marking Guide
Marks will be awarded for the appropriate use of data structures and the efficiency of the program at processing the input and producing the correct output. Marks may be deducted for untidy or poorly designed code. Appropriate comments should be provided where needed. There will be a deduction of up to 4 marks for using STL, or equivalent libraries, rather than coding the data structures and algorithms yourself. You may use string or String type for storing words or text, if you wish. All coding and comments must be your own work.   Submission: Assignments should be typed into a single text file named "ass2.ext" where "ext" is the appropriate file extension for the chosen language. You should run your program and copy and paste the output into a text file named: "output.txt"   Submit your files via the submit program on banshee:                  submit -u user -c csci203 -a 2 ass1.ext output.txt      - where user is your unix userid and ext is the extn of your code file. Late assignment submissions without granted extension will be marked but the points awarded will be reduced by 1 mark for each day late.  Assignments will not be accepted if more than five days late. An extension of time for the assignment submission may be granted in certain circumstances.  Any request for an extension of the submission deadline must be made via SOLS before the submission deadline. Supporting documentation should accompany the request for any extension. Read the full article
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:               service_time  =  (tally_time  x  efficiency)  +  payment_time            where:                   tally_time:  time it takes to tally up the customer's goods                   efficiency:  the efficiency of the server                  payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue
Tumblr media
Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.
Tumblr media
Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()             Declare variables and instances and do initialisations             Open the input data file;  if not found print error and exit           Read first CustomerArrival event from file and add it to the event queue      While the event queue is not empty . . .                        Get the next event from the event queue and set CrntTime to the event time                            If the event type = CustomerArrival event . . .                                            if an idle server is available . . .                                                    Find fastest idle serve                                                      set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                   add ServerFinish event to the event queue                                  Else                                           Add event's customer to the customer queue                                  End if                                  If not EOF . . .                                                    Read next customer arrival from file                                        add CustomerArrival event to the event queue                                  End if                        Else // event type must be a ServerFinish event . . .                                      Get server no. from event, set server to idle and do server's stats                               If customer queue is not empty . . .                                                    Get next customer from the customer queue                                                  Find fastest idle serve                                                     set the server’s idle flag to busy.                                            calculate the server’s finish time                                                add ServerFinish event to the event queue                                  End if                       End if            End while             Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java: javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.  
Marking Guide
Marks will be awarded for the appropriate use of data structures and the efficiency of the program at processing the input and producing the correct output. Marks may be deducted for untidy or poorly designed code. Appropriate comments should be provided where needed. There will be a deduction of up to 4 marks for using STL, or equivalent libraries, rather than coding the data structures and algorithms yourself. You may use string or String type for storing words or text, if you wish. All coding and comments must be your own work.   Submission: Assignments should be typed into a single text file named "ass2.ext" where "ext" is the appropriate file extension for the chosen language. You should run your program and copy and paste the output into a text file named: "output.txt"   Submit your files via the submit program on banshee:                  submit -u user -c csci203 -a 2 ass1.ext output.txt      - where user is your unix userid and ext is the extn of your code file. Late assignment submissions without granted extension will be marked but the points awarded will be reduced by 1 mark for each day late.  Assignments will not be accepted if more than five days late. An extension of time for the assignment submission may be granted in certain circumstances.  Any request for an extension of the submission deadline must be made via SOLS before the submission deadline. Supporting documentation should accompany the request for any extension. Read the full article
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:                 service_time  =  (tally_time  x  efficiency)  +  payment_time         where:                   tally_time:  time it takes to tally up the customer's goods                    efficiency:  the efficiency of the server                   payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue   Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.   Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()           Declare variables and instances and do initialisations           Open the input data file;  if not found print error and exit          Read first CustomerArrival event from file and add it to the event queue     While the event queue is not empty . . .                     Get the next event from the event queue and set CrntTime to the event time                      If the event type = CustomerArrival event . . .                                   if an idle server is available . . .                                             Find fastest idle serve                                                 set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                add ServerFinish event to the event queue                              Else                                        Add event's customer to the customer queue                               End if                               If not EOF . . .                                             Read next customer arrival from file                                  add CustomerArrival event to the event queue                               End if                     Else // event type must be a ServerFinish event . . .                                 Get server no. from event, set server to idle and do server's stats                              If customer queue is not empty . . .                                             Get next customer from the customer queue                                             Find fastest idle serve                                                 set the server’s idle flag to busy.                                        calculate the server’s finish time                                             add ServerFinish event to the event queue                               End if                     End if           End while           Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java:    javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.     Read the full article
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:                 service_time  =  (tally_time  x  efficiency)  +  payment_time         where:                   tally_time:  time it takes to tally up the customer's goods                    efficiency:  the efficiency of the server                   payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue   Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.   Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()           Declare variables and instances and do initialisations           Open the input data file;  if not found print error and exit          Read first CustomerArrival event from file and add it to the event queue     While the event queue is not empty . . .                     Get the next event from the event queue and set CrntTime to the event time                      If the event type = CustomerArrival event . . .                                   if an idle server is available . . .                                             Find fastest idle serve                                                 set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                add ServerFinish event to the event queue                              Else                                        Add event's customer to the customer queue                               End if                               If not EOF . . .                                             Read next customer arrival from file                                  add CustomerArrival event to the event queue                               End if                     Else // event type must be a ServerFinish event . . .                                 Get server no. from event, set server to idle and do server's stats                              If customer queue is not empty . . .                                             Get next customer from the customer queue                                             Find fastest idle serve                                                 set the server’s idle flag to busy.                                        calculate the server’s finish time                                             add ServerFinish event to the event queue                               End if                     End if           End while           Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java:    javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.     Read the full article
0 notes
felord · 6 years ago
Text
CSCI203/CSCI803 ASSIGNMENT 2 Solved
You have been hired by a major supermarket chain to model the operation of a proposed supermarket by using a Discrete Event Simulation. The shop has several servers (or checkouts), each of which has a different level of efficiency due to the experience of the server operator. It also takes longer to serve credit card customers. The service time of each customer is calculated as follows:                 service_time  =  (tally_time  x  efficiency)  +  payment_time         where:                   tally_time:  time it takes to tally up the customer's goods                    efficiency:  the efficiency of the server                   payment_time:  0.3 for cash or 0.7 for credit card The input file “ass2.txt” contains the records of each customer entering the shop and consist of:  arrival time (at the server queue), tally time (time it takes to scan the customer's items and add up the cost) payment method (cash or card). Your program should: Open the text file “ass2.txt” (Note: “ass2.txt” should be a hardcoded as a constant.) 2. Read the efficiencies of each server. Read and process the customer arrival and service time data. Print service statistics on the screen. Note: This shop has a single queue of customers waiting to be served. The servers are initially all idle. If more than one idle server is available, the next customer is served by the server with the best efficiency (i.e. the smallest efficiency value). Customers must be served or queued in the order in which they arrive. You should not attempt to read in all the arrival data at the start of the simulation. At the end of the simulation, after the last customer in the file has been served, your program should print out the following information: The number of customers served. The time that it took to serve all the customers. The greatest length reached by the customer queue. The average length of the customer queue. The average time spent by a customer in the customer queue. (If a customer is served immediately, their queue time is 0.0). The percentage of customers who’s waiting time in the customer queue was 0 (zero). For each server: The number of customers they served The time they spent idle. You must choose appropriate data structures and algorithms to accomplish this task quickly. You will lose marks if you use STL, or equivalent libraries, to implement data structures or algorithms.  Note: A larger input data file may be used for the final assessment of your program.    
Step-1 (Week-7 demo, 2 marks)
For step 1 you are to implement the simulator’s customer queue and event queue. Implement the customer queue (FIFO queue). It should have a maximum size of 500 records. Each record in the customer queue should contain two doubles and a boolean (i.e. arrival time, tally time and payment method). Your customer queue should have functions for adding an item (enqueue), removing an item (dequeue), and for testing if the queue is empty. (Note: C++ and Java coders should also add a constructor for initialsing the queue.) FIFO Queue   Test your customer queue by declaring an instance of it in the main(). Use a for loop to add 10 records to the queue. Set the arrival time for each record between 1 and 100 using rand() or random(). The other fields can be set to 0 or false. Also, print the arrival times on the screen as you add them. Now use a while loop to remove all the records from the customer queue and print the arrival times on the screen. Is the output correct? Now implement the simulator's event queue (i.e. a priority queue). The event queue’s records should contain an event type (int or enum), event time & tally time (doubles), and   payment method (boolean).  You can assume the maximum number of events in the event queue is 100. The record with the minimum event time has the highest priority.   Test the event queue by declaring an instance of it in the main(). Use the while loop (implemented previously) to remove records from the customer queue and add them to the event queue. Set the event time with the customer's arrival time. Set the other fields to zero. Then implement a while loop in the main() to remove (dequeue) each record from the event queue and print the event time on the screen. Is the output correct? Note: For step-1 (to get the 2 demo marks) you can implement the customer and event queues using any method you like. However, for the final submission, to get full marks, you should ensure all data structures and algorithms are optimised for speed.              
Step-2 (Server array implementation)
The server array should have a maximum of 20 servers. Each server should have a busy flag (boolean), an efficiency factor (double) and other data members for calculating the stats. C++ and Java coders should implement the server array with a class, preferably, and provide public functions for adding, and removing customers to/from the servers, finding the fasted idle server, etc. according to the specs on page 1.  
Step-3 (Processing in the data)
When you have the customer queue, event queue and server array correctly completed, delete the main() test code from step 1 and replace it with code for reading the input data file “ass2.txt” and processing the data, as explained on page 1. The following algorithm shows how a typical discrete time simulator can be implemented: main()           Declare variables and instances and do initialisations           Open the input data file;  if not found print error and exit          Read first CustomerArrival event from file and add it to the event queue     While the event queue is not empty . . .                     Get the next event from the event queue and set CrntTime to the event time                      If the event type = CustomerArrival event . . .                                   if an idle server is available . . .                                             Find fastest idle serve                                                 set the server’s idle flag to busy                                                 calculate the server’s finish time from event's customer data                                                add ServerFinish event to the event queue                              Else                                        Add event's customer to the customer queue                               End if                               If not EOF . . .                                             Read next customer arrival from file                                  add CustomerArrival event to the event queue                               End if                     Else // event type must be a ServerFinish event . . .                                 Get server no. from event, set server to idle and do server's stats                              If customer queue is not empty . . .                                             Get next customer from the customer queue                                             Find fastest idle serve                                                 set the server’s idle flag to busy.                                        calculate the server’s finish time                                             add ServerFinish event to the event queue                               End if                     End if           End while           Print stats End main()                                                   
Step-4 (Optimisation and stats)
When you have the discrete time simulation working correctly, add the necessary data members and variables needed for calculating all the required stats, as explained on page 1, and optimise your simulator for speed.
Step-5 (Specifications)
In a comment block at the bottom of your program (no more than 20 lines of text) list all the data structures and algorithms used by your program to process the input data. Include any enhancements you did to speed up your program (if any). For this step, marks will be awarded based on how accurately and clearly you describe your program.  
Compilation
All programs submitted must compile and run on banshee:
C:     gcc ass2.c  C++:      g++ ass2.cpp Java:    javac ass2.java Python: python ass2.py
      Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly.     Read the full article
0 notes